import openai

openai.api_key = "your_api"


def generate_response(prompt, model):
    completions = openai.Completion.create(
        engine=model,
        prompt=prompt,
        max_tokens=1024,
        n=1,
        stop=None,
        temperature=0.7,
        frequency_penalty=0.1,
        presence_penalty=0.1
    )
    message = completions.choices[0].text
    return message.strip()


print("文心一言很高兴为您服务")
while True:
    user_input = input("您：")
    prompt = f"User: {user_input} \n文心一言:"

    response = generate_response(prompt, "davinci")
    print("文心一言: ", response)
